package com.gitee.wsl.common.ui.ext.color

import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.graphics.ColorMatrix

fun ColorFilter.Companion.brightnessContrast(contrast: Float = 2f, // 0f..10f (1 should be default),
                                             brightness: Float = -180f // -255f..255f (0 should be default)
): ColorFilter {
    val colorMatrix = floatArrayOf(
        contrast, 0f, 0f, 0f, brightness,
        0f, contrast, 0f, 0f, brightness,
        0f, 0f, contrast, 0f, brightness,
        0f, 0f, 0f, 1f, 0f
    )
    return colorMatrix(ColorMatrix(colorMatrix))
}

fun ColorFilter.Companion.invertColor(): ColorFilter {
    val colorMatrix = floatArrayOf(
        -1f, 0f, 0f, 0f, 255f,
        0f, -1f, 0f, 0f, 255f,
        0f, 0f, -1f, 0f, 255f,
        0f, 0f, 0f, 1f, 0f
    )
    return colorMatrix(ColorMatrix(colorMatrix))
}